package com.xtecher.app.utils;

import android.app.ProgressDialog;
import android.content.Context;

/**
 * 对话框工具类
 * Created by \(^o^)/~ on 2016/7/11.
 */
public class DialogUtil {


    private static ProgressDialog dialog;

    public static void showProgress(Context context, String msg) {
        showProgress(context, msg, false);
    }

    public static void showProgress(Context context, String msg, boolean isCancel) {
        if (dialog == null) {
            dialog = new ProgressDialog(context);
            dialog.setProgressStyle(ProgressDialog.STYLE_SPINNER);
            dialog.setCancelable(isCancel);
            dialog.setMessage(msg);
            dialog.show();
            dialog.setOnCancelListener(dialog1 -> dialog = null);
        }
    }


    public static void closeProgress() {
        if (dialog != null && dialog.isShowing()) {
            dialog.dismiss();
            dialog = null;
        }
    }
}
